package com.zitangkou.user.domain.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zitangkou.user.domain.IUserPermissionDomainService;
import com.zitangkou.user.domain.UserPermissionDomain;
import com.zitangkou.user.domain.converter.IUserPermissionDomainConverter;
import com.zitangkou.user.entity.UserPermissionDo;
import com.zitangkou.common.enums.StatusEnum;
import com.zitangkou.user.mapper.UserPermissionMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Deng Ningning
 * @version 1.0
 * @date 2020/11/13 21:59
 */
@Service
public class UserPermissionDomainServiceImpl implements IUserPermissionDomainService {

    @Resource
    private UserPermissionMapper userPermissionMapper;

    @Resource
    private IUserPermissionDomainConverter userPermissionDomainConverter;

    @Override
    public List<UserPermissionDomain> selectPermissionsByUserId(String userId) {
        return userPermissionDomainConverter.toDomainList(userPermissionMapper.selectList(new LambdaQueryWrapper<UserPermissionDo>()
                .eq(UserPermissionDo::getStatus, StatusEnum.ENABLED).eq(UserPermissionDo::getUserId, userId)));
    }
}
